Skip to content
This repository has been archived by the owner on Sep 23, 2023. It is now read-only.

Txpool 4844 upgrades Part 2 #1125

Merged
merged 31 commits into from
Sep 20, 2023
Merged

Txpool 4844 upgrades Part 2 #1125

merged 31 commits into from
Sep 20, 2023

Conversation

somnathb1
Copy link
Collaborator

@somnathb1 somnathb1 commented Sep 13, 2023

Fix some peer-review comments from the last related PR, and add some enhancements

Change summary

  • Addition of a flag for BlobSlots - for max allowed blobs per account in txpool
  • Use BlobFee from the block to validate txs in the pool
  • Let go of unwound blob txn's onNewBlock, if not present in the cache; we don't request them again from the network

Related: erigontech/erigon#8213 erigontech/interfaces#195

@somnathb1 somnathb1 marked this pull request as draft September 13, 2023 12:15
@somnathb1 somnathb1 changed the title Txpool 4844 upgrades Part 2 [Do not merge] Txpool 4844 upgrades Part 2 Sep 15, 2023
@somnathb1 somnathb1 changed the title [Do not merge] Txpool 4844 upgrades Part 2 Txpool 4844 upgrades Part 2 Sep 16, 2023
@somnathb1 somnathb1 marked this pull request as ready for review September 16, 2023 12:15
txpool/pool.go Outdated
func (p *TxPool) setBlobFee(blobFee uint64) (uint64, bool) {
changed := false
if blobFee > 0 {
changed = blobFee != p.pendingBlobFee.Load()
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

“Read then write” on atomic - it’s race-condition. Please use CompareAndSwap operation.

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

That's the only place of writing that variable tho, but there is a bit of unnecessary code here. Removing it.

txpool/pool.go Outdated
if _, ok := p.minedBlobTxsByHash[string(mt.Tx.IDHash[:])]; ok {
p.deleteMinedBlobTxn(string(mt.Tx.IDHash[:]))
// Don't add blob tx to queued if it's less than current pending blob base fee
if mt.Tx.Type == types.BlobTxType && mt.Tx.BlobFeeCap.Cmp(uint256.NewInt(p.pendingBlobFee.Load())) < 0 {
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

uint256 has method Less

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Changed it to native uint64 comparison

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Switched to using uint256's CmpUint64() and LtUint64() methods

txpool/pool.go Outdated
logger log.Logger) {
// Demote worst transactions that do not qualify for pending sub pool anymore, to other sub pools, or discard
for worst := pending.Worst(); pending.Len() > 0 && (worst.subPool < BaseFeePoolBits || worst.minFeeCap.Cmp(uint256.NewInt(pendingBaseFee)) < 0); worst = pending.Worst() {
for worst := pending.Worst(); pending.Len() > 0 && (worst.subPool < BaseFeePoolBits || worst.minFeeCap.Cmp(uint256.NewInt(pendingBaseFee)) < 0 || (worst.Tx.Type == types.BlobTxType && worst.Tx.BlobFeeCap.Cmp(uint256.NewInt(pendingBlobFee)) < 0)); worst = pending.Worst() {
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Can we avoid “NewInt” inside loop - for optimization. Because we are also inside global mutex of txpool - and better unlock it as fast as possible.

Copy link
Collaborator Author

@somnathb1 somnathb1 Sep 17, 2023

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Changed it to native uint64 conversion and then comparison

Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Is it in “wei”? Can it have uint64 overflow?

Copy link
Collaborator Author

@somnathb1 somnathb1 Sep 18, 2023

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Eventually comes from the submitted transaction, theoretically it could have an overflow. So could the block's baseFee. I will make the worst assumptions here and rather use uint256 everywhere.
Practically, it may not matter, but for expanding support to other chains later, with much lower native token values, it could be useful.

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Switched to using uint256's CmpUint64() and LtUint64() methods

Copy link
Collaborator

@AskAlexSharov AskAlexSharov left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

  • i’m not sure that it’s safe to cast any uint256 to uint64, because it can be bigger than uint64
  • please take a look at existing fuzzing tests for txpool - are they still work? Need add there new check?

go.sum Show resolved Hide resolved
txpool/pool_test.go Outdated Show resolved Hide resolved
txpool/fetch.go Show resolved Hide resolved
@somnathb1 somnathb1 dismissed AskAlexSharov’s stale review September 20, 2023 11:23

Regarding fuzz tests: Existing ones work. For changes specific to this PR, unit tests and Hive tests would be used to test these. I could introduce few changes/additions to txpool fuzz tests targeted at the changes for 4844

@somnathb1 somnathb1 added this pull request to the merge queue Sep 20, 2023
Merged via the queue into main with commit 93d9c9d Sep 20, 2023
3 checks passed
@somnathb1 somnathb1 deleted the txpool-4844-upgrades branch September 20, 2023 11:23
somnathb1 added a commit to erigontech/erigon that referenced this pull request Sep 20, 2023
Some peer-review changes from the last related PR. 
Addition of a flag for BlobSlots - for max allowed blobs per account in
txpool.
Use BlobFee from the block to validate txs in the pool.

See also ledgerwatch/erigon-lib#1125
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants